
// src/components/PrivateRoute.tsx
import React from 'react';
import { Navigate } from 'react-router-dom';

interface PrivateRouteProps {
  children: React.ReactNode;
}

const PrivateRoute: React.FC<PrivateRouteProps> = ({ children }) => {
  const isAuthenticated = !!localStorage.getItem('token'); // 检查认证状态
  return isAuthenticated ? <>{children}</> : <Navigate to="/login" />; // 重定向
};

export default PrivateRoute;


// import React from 'react';
// import { Navigate, Outlet } from 'react-router-dom';

// const PrivateRoute: React.FC = () => {
//   const accessToken = localStorage.getItem('access_token');
//   return accessToken ? <Outlet /> : <Navigate to="/login" replace />;
// };

// export default PrivateRoute;